package com.ruoyi.web.controller.common;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.lowcode.domain.bo.LcDatabaseSourceBo;
import com.ruoyi.lowcode.domain.bo.SQLBo;
import com.ruoyi.lowcode.service.ISQLService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/lowcode")
public class SQLController {

    private final ISQLService sqlService;

    /**
     * 通用sql查询
     *
     * @param sqlBo
     * @return
     */
    @PostMapping("/selectListSql")
    public R selectListSql(@Validated @RequestBody SQLBo sqlBo) throws ClassNotFoundException {
        return R.ok(sqlService.selectListSql(sqlBo));
    }

    /**
     * 测试数据源连接
     *
     * @param bo
     * @return
     */
    @PostMapping("/testConnection")
    public R testConnection(@Validated @RequestBody LcDatabaseSourceBo bo) throws ClassNotFoundException {
        return R.ok(sqlService.testConnection(bo));
    }

}
